//获取cookie
var cookieStr = document.cookie;
var cookieArr = cookieStr.split(";");
var orderCookie = bubbleSort(cookieArr);
var timesArr = SortArray(orderCookie);

var firstItem = timesArr[0],secondItem = timesArr[1],thirdItem = timesArr[2],fourthItem = timesArr[3];

firstItem ? firstItem : $("#firstIcon").attr("href","http://ykt.cuc.edu.cn/").find('p').html('一卡通业务');
secondItem ? secondItem : $("#secondIcon").attr("href","http://zcsp.cuc.edu.cn:81/").find('p').html('后勤业务审批');
thirdItem ? thirdItem : $("#thirdIcon").attr("href","http://cwcpt.cuc.edu.cn/dlpt/Newindex.aspx").find('p').html('财务网上平台');
fourthItem ? fourthItem : $("#fourthIcon").attr("href","http://202.205.18.230:9799/zcgl").find('p').html('资产管理系统');


console.log(timesArr);
var len = timesArr.length;
if(len > 4) {
    var recommendArr = timesArr.slice(0,4);
    for (var i = 0; i < recommendArr.length; i++) {
        var itemCookie = recommendArr[i];
        var itemName = itemCookie.split("=")[0];
        itemName = $.trim(itemName);
        $(".icons-content li a").each(function(){
            if(i == 0) {
                if(itemName == $(this).attr('id')) {
                    $("#firstIcon").attr('href',$(this).attr('href'));
                    $("#firstIcon").find('p').html($(this).find('span').html());
                }
            } else if(i == 1) {
                if(itemName == $(this).attr('id')) {
                    $("#secondIcon").attr('href',$(this).attr('href'));
                    $("#secondIcon").find('p').html($(this).find('span').html());
                }
            } else if(i == 2) {
                 if(itemName == $(this).attr('id')) {
                    $("#thirdIcon").attr('href',$(this).attr('href'));
                    $("#thirdIcon").find('p').html($(this).find('span').html());
                }
            } else if(i == 3) {
                if(itemName == $(this).attr('id')) {
                    $("#fourthIcon").attr('href',$(this).attr('href'));
                    $("#fourthIcon").find('p').html($(this).find('span').html());
                }
            }
        });
    }
}





function SortArray(arr) {
    var len = arr.length;
    for (var i = 0; i < len; i++) {
        for (var j = 0; j < len - 1 - i; j++) {
            var itemObj1 = JSON.parse(arr[j].split("=")[1]);
            var item1 = itemObj1.c;
            var itemObj2 = JSON.parse(arr[j + 1].split("=")[1]);
            var item2 = itemObj2.c;
            if (item1 < item2) {
                var temp = arr[j + 1];
                arr[j + 1] = arr[j];
                arr[j] = temp;
            }
        }
    }
    return arr;
}